$(document).ready(function(){	
	$("#addUser").val(username);
	
 	$("#writeTime").datetimepicker({lang:'ch',
 		timepicker:false,
 		format:'Y-m-d',
 		formatDate:'Y-m-d'
 	});
 	
 	$("input[type=file]").change(function(){
 		
		ajaxfileuploadUtil(this,"article");
	});

//表单验证
var validate = $("#fromSpecialArticle").validate({		   
		rules:{					
			title:{
				  required:true,
			      remote: { 
	                   url: server_url+'/rest/SpecialArticle/checkTitle.do?timestamp='+Math.random()+ '&token=' + token,
	                   type: "post",
	                   dataType: "json", 
	                   data: {			                	     
	                	         title: function() { return $("#title").val();}
	                         } 
	               },
	               stringMaxLength:30
			},
			articleType:{
			   required:true			  
		   },		  
		   keyWords:{
			   required:true
		   }, 
		   sort:{
			   required:true
		   },
		   author:{
			   required:true
		   },
		   content:{
			   required:true
		   } 
			
		},
		messages:{				
			title:{
			      required:"不能为空！",
                  remote:"已存在!",
                  stringMaxLength:"最多能输入30个字符！"
                 },
           articleType:{
            	 required:"不能为空！"
             },
             keyWords:{
            	required:"不能为空！"            		
            },
            sort:{
            	required:"不能为空！"            		
            },
            author:{
            	required:"不能为空！"            		
            },
            content:{
            	required:"不能为空！"            		
            }
		},
		submitHandler:function(){
			sub();
		},
		errorPlacement: function(error, element) {
			if ( element.is(":radio") )
				error.appendTo ( element.parent() );
			else if ( element.is(":checkbox") )
				error.appendTo ( element.parent() );
			else if ( element.is("input[name=captcha]") )
				error.appendTo ( element.parent() );
			else
				error.insertAfter(element);
		},
		validClass : 'rightValidate',
	    success: function(label) {
		   label.html("&nbsp;").text(" ") ;
	    }
 });
   

});


//提交
function sub(){	
		if($("#fromSpecialArticle").valid()){
			$.ajax({
				url:server_url+'/rest/SpecialArticle/SpecialArticleAdd.do?ran='+Math.random()+ '&token=' + token,
				type:'post',
				data:$("#fromSpecialArticle").serialize(),
				success:function(data){
					easyDialog.open({container:{header:'温馨提示',content:data.retMsg},autoClose : 2000});
					back();
				}
			});
		}	
}



function back(){
	
	var url="getSpecialArticleListPage.do?ran="+Math.random();
	tl_config.loadToWorkArea(url);
}

function submitCommit(){
	$("#fromSpecialArticle").submit();
}
